home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / include / RCS / option.h,v < prev    next >
Encoding:
Text File  |  1991-01-28  |  7.9 KB  |  333 lines

  1. head     1.8;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.8
  10. date     91.01.28.12.30.55;  author kupfer;  state Exp;
  11. branches ;
  12. next     1.7;
  13.  
  14. 1.7
  15. date     89.06.23.11.27.50;  author rab;  state Exp;
  16. branches ;
  17. next     1.6;
  18.  
  19. 1.6
  20. date     88.11.21.18.04.12;  author douglis;  state Exp;
  21. branches ;
  22. next     1.5;
  23.  
  24. 1.5
  25. date     88.08.04.08.29.21;  author ouster;  state Exp;
  26. branches ;
  27. next     1.4;
  28.  
  29. 1.4
  30. date     88.08.01.17.14.04;  author ouster;  state Exp;
  31. branches ;
  32. next     1.3;
  33.  
  34. 1.3
  35. date     88.08.01.12.14.07;  author ouster;  state Exp;
  36. branches ;
  37. next     1.2;
  38.  
  39. 1.2
  40. date     88.08.01.12.09.47;  author ouster;  state Exp;
  41. branches ;
  42. next     1.1;
  43.  
  44. 1.1
  45. date     88.08.01.10.42.35;  author ouster;  state Exp;
  46. branches ;
  47. next     ;
  48.  
  49.  
  50. desc
  51. @@
  52.  
  53.  
  54. 1.8
  55. log
  56. @Add OPT_TIME flavor.  Use _ARGS_ instead of comments in the procedure
  57. declarations.
  58. @
  59. text
  60. @/*
  61.  * option.h --
  62.  *    This defines the Option type and the interface to the
  63.  *    Opt_Parse library call that parses command lines.
  64.  *
  65.  * Copyright 1988, 1991 Regents of the University of California
  66.  * Permission to use, copy, modify, and distribute this
  67.  * software and its documentation for any purpose and without
  68.  * fee is hereby granted, provided that the above copyright
  69.  * notice appear in all copies.  The University of California
  70.  * makes no representations about the suitability of this
  71.  * software for any purpose.  It is provided "as is" without
  72.  * express or implied warranty.
  73.  *
  74.  * $Header: /sprite/src/lib/include/RCS/option.h,v 1.7 89/06/23 11:27:50 rab Exp Locker: kupfer $ SPRITE (Berkeley)
  75.  */
  76.  
  77. #ifndef _OPTION
  78. #define _OPTION
  79.  
  80. #include <cfuncproto.h>
  81.  
  82. /*
  83.  * An array of option descriptions (type Option) is passed into the
  84.  * routine which interprets the command line.  Each option description
  85.  * includes the key-string that indicates the option, a type for the option,
  86.  * the address of an associated variable, and a documentation message
  87.  * that is printed when the command is invoked with a single argument
  88.  * of '?'
  89.  */
  90.  
  91. typedef struct Option {
  92.     int        type;        /* Indicates option type;  see below */
  93.     char    *key;        /* The key string that flags option */
  94.     char *    address;    /* Address of variable to modify */
  95.     char    *docMsg;    /* Documentation message */
  96. } Option;
  97. /*
  98.  * Values for type:
  99.  *
  100.  *    OPT_CONSTANT(val) -    if the flag is present then set the
  101.  *                associated (integer) variable to val.
  102.  *                Val must be a non-negative integer.
  103.  *    OPT_TRUE -        if the flag is present then set the
  104.  *                associated (integer) variable to TRUE (1).
  105.  *    OPT_FALSE -        if the flag is present then set the
  106.  *                associated (integer) variable to FALSE (0).
  107.  *    OPT_INT -        if the flag is present then the next argument
  108.  *                on the command line is interpreted as an
  109.  *                integer and that value is assigned to the
  110.  *                options associated variable.
  111.  *    OPT_STRING -        if the flag is present then the next argument
  112.  *                on the command line is copied into the string
  113.  *                variable associated with the option.
  114.  *    OPT_REST -        if the flag is present, inhibit processing of
  115.  *                later options, so that they're all returned
  116.  *                to the caller in argv.  In addition, set the
  117.  *                associated variable to the index of the first
  118.  *                of these arguments in the returned argv.
  119.  *                This permits a program to allow a flag to
  120.  *                separate its own options from options it will
  121.  *                pass to another program.
  122.  *    OPT_FLOAT -        if the flag is present then the next argument
  123.  *                on the command line is interpreted as a
  124.  *                "double" and that value is assigned to the
  125.  *                option's associated variable.
  126.  *    OPT_TIME -        if the flag is present then the next argument 
  127.  *                on the command line is interpreted as a date 
  128.  *                and time.  The corresponding time value 
  129.  *                (number of seconds past the epoch) is assigned
  130.  *                to the option's associated variable.
  131.  *    OPT_FUNC -        if the flag is present, pass the next argument
  132.  *                to "address" as a function. The function
  133.  *                should be declared:
  134.  *                    int
  135.  *                    func(optString, arg)
  136.  *                    char     *optString;
  137.  *                    char    *arg;
  138.  *                    Func should return non-zero if the argument
  139.  *                was consumed or zero if not.  "optString" is
  140.  *                the option key string that caused the
  141.  *                function to be called and "arg" is the next
  142.  *                argument (if there is no next argument then
  143.  *                "arg" will be NULL).
  144.  *    OPT_GENFUNC -        if the flag is present, pass the remaining
  145.  *                arguments and the number of arguments to
  146.  *                "address" as a function. The function should
  147.  *                be declared:
  148.  *                    int
  149.  *                    func(optString, argc, argv)
  150.  *                    char *optString;
  151.  *                    int argc;
  152.  *                    char **argv;
  153.  *                and should return the new number of arguments
  154.  *                left in argv.  argv should have been shuffled
  155.  *                to eliminate the arguments func consumed.
  156.  *    OPT_DOC -        a dummy entry. Exists mostly for its
  157.  *                documentation string.  As an additional side
  158.  *                effect, if its key string an argument,
  159.  *                Opt_Parse will treat it like a question mark
  160.  *                (i.e. print out the program's usage and exit).
  161.  */
  162.  
  163. #define OPT_CONSTANT(val)    ((int) val)
  164. #define OPT_FALSE        0
  165. #define OPT_TRUE        1
  166. #define OPT_INT            -1
  167. #define OPT_STRING        -2
  168. #define OPT_REST        -3
  169. #define OPT_FLOAT        -4
  170. #define OPT_FUNC        -5
  171. #define OPT_GENFUNC        -6
  172. #define OPT_DOC            -7
  173. #define OPT_TIME        -8
  174.  
  175. /*
  176.  * Flag values for Opt_Parse:
  177.  *
  178.  * OPT_ALLOW_CLUSTERING -    Permit many flags to be clustered under
  179.  *                a single "-".  In otherwords, treat
  180.  *                "foo -abc" the same as "foo -a -b -c".
  181.  * OPT_OPTIONS_FIRST    -    Stop parsing if something other than an
  182.  *                option (starting with a hyphen) is encountered.
  183.  */
  184.  
  185. #define OPT_ALLOW_CLUSTERING    1
  186. #define OPT_OPTIONS_FIRST    2
  187.  
  188. /*
  189.  * Exported procedures:
  190.  */
  191.  
  192. int Opt_Parse _ARGS_ ((int argc, char *argv[], Option *optionArray, 
  193.                int numOptions, int flags));
  194.  
  195. void Opt_PrintUsage _ARGS_ ((char *commandName, Option *optionArray,
  196.                  int numOptions));
  197.  
  198. /*
  199.  * Macro to determine size of option array:
  200.  */
  201.  
  202. #define Opt_Number(optionArray)    (sizeof(optionArray)/sizeof((optionArray)[0]))
  203.  
  204. #endif /* _OPTION */
  205. @
  206.  
  207.  
  208. 1.7
  209. log
  210. @*** empty log message ***
  211. @
  212. text
  213. @d6 1
  214. a6 1
  215.  * Copyright 1988 Regents of the University of California
  216. d15 1
  217. a15 1
  218.  * $Header: /sprite/src/lib/include/RCS/option.h,v 1.6 88/11/21 18:04:12 douglis Exp Locker: rab $ SPRITE (Berkeley)
  219. d21 2
  220. d67 5
  221. d114 1
  222. d133 5
  223. a137 13
  224. int
  225. Opt_Parse( /* int argc;
  226.           char *argv[];
  227.           Option *optionArray;
  228.           int numOptions;
  229.           int flags;
  230.       */ );
  231.  
  232. void
  233. Opt_PrintUsage( /* char *commandName;
  234.            Option *optionArray;
  235.            int numOptions;
  236.              */ );
  237. @
  238.  
  239.  
  240. 1.6
  241. log
  242. @added OPT_OPTIONS_FIRST option.
  243. @
  244. text
  245. @d15 1
  246. a15 1
  247.  * $Header: /sprite/src/lib/include/RCS/option.h,v 1.5 88/08/04 08:29:21 ouster Exp Locker: douglis $ SPRITE (Berkeley)
  248. d145 1
  249. a145 1
  250. #endif _OPTION
  251. @
  252.  
  253.  
  254. 1.5
  255. log
  256. @Changed allowClustering from a Boolean to a general flags word.
  257. @
  258. text
  259. @d15 1
  260. a15 1
  261.  * $Header: option.h,v 1.4 88/08/01 17:14:04 ouster Exp $ SPRITE (Berkeley)
  262. d114 2
  263. d119 1
  264. @
  265.  
  266.  
  267. 1.4
  268. log
  269. @Eliminate obsolete typedef.
  270. @
  271. text
  272. @d15 1
  273. a15 1
  274.  * $Header: option.h,v 1.3 88/08/01 12:14:07 ouster Exp $ SPRITE (Berkeley)
  275. d109 10
  276. d127 1
  277. a127 1
  278.           int allowClustering;
  279. @
  280.  
  281.  
  282. 1.3
  283. log
  284. @Redeclare Opt_Parse.
  285. @
  286. text
  287. @d15 1
  288. a15 1
  289.  * $Header: option.h,v 1.1 88/08/01 10:42:35 ouster Exp $ SPRITE (Berkeley)
  290. a28 13
  291.  
  292. typedef enum {
  293.     OPT_TRUE,        /* Set *address TRUE */
  294.     OPT_FALSE,        /* Set *address FALSE */
  295.     OPT_INT,        /* Set *address to next arg as an integer */
  296.     OPT_STRING,        /* Set *address to next arg */
  297.     OPT_REST,        /* Ignore the rest of the arguments */
  298.     OPT_FLOAT,        /* Set *address to next arg as a float */
  299.     OPT_FUNC,        /* Use address as a function to process next arg */
  300.     OPT_GENFUNC,      /* Use address as a function to process as many
  301.              * arguments as it wants */
  302.     OPT_DOC        /* Not a real option, just documentation */
  303. } OptionType;
  304. @
  305.  
  306.  
  307. 1.2
  308. log
  309. @Change parameter order.
  310. @
  311. text
  312. @d125 1
  313. a125 1
  314. void
  315. @
  316.  
  317.  
  318. 1.1
  319. log
  320. @Initial revision
  321. @
  322. text
  323. @d15 1
  324. a15 1
  325.  * $Header: proto.h,v 1.2 88/03/11 08:39:40 ouster Exp $ SPRITE (Berkeley)
  326. d128 1
  327. a129 1
  328.           Option *optionArray;
  329. d135 1
  330. a136 1
  331.            Option *optionArray;
  332. @
  333.